package ltd.sshine.networkserver.holder;

import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 客户端连接持有者
 */
@Component
public class ClientConnectHolder {
    private static final Map<Integer, Channel> hostServer=new ConcurrentHashMap<>();

    public static void add(Integer port,Channel channel){
        hostServer.put(port,channel);
    }
    public static void delete(Integer port){
        Channel remove = hostServer.remove(port);
        //todo 实现关闭
        remove.close();
    }
    public static boolean hasPort(Integer port){
      return   hostServer.containsKey(port);
    }
    public static List<Integer> getPorts(){
        return new ArrayList<>(hostServer.keySet());
    }

}
